import 'package:acgn_pioneer/models/base_model.dart';

/// 日志打印
class Console {
  // static bool _debugMode = false; //是否是debug模式,true: log v 不输出.

  static void init({
    bool isDebug = false,
  }) {
    // _debugMode = isDebug;
  }

  static void log(
    Object l, {
    Object l1,
    Object l2,
    Object l3,
    Object l4,
  }) {
    String log = '';
    log += concatLog(l);
    log += concatLog(l1);
    log += concatLog(l2);
    log += concatLog(l3);
    log += concatLog(l4);
    print(log);
  }

  static concatLog(Object o) {
    if (o == null) {
      return '';
    }
    return ' ' + getObjectInfo(o);
  }

  static List<String> internalTypes = [
    'int',
    'double',
    'String',
    'Boolean',
    'List',
    '_CompactLinkedHashSet',
    '_InternalLinkedHashMap'
  ];

  static String getObjectInfo(Object o) {
    var type = o.runtimeType.toString();
    if (internalTypes.any((i) => type.indexOf(i) != -1)) {
      return o.toString();
    }
    try {
      return (o as BaseModel).toJson().toString();
    } catch (ex) {
      return o.toString();
    }
  }
}

/// 导出全局使用
var console = Console.log;
